# +--------------------------
# | User: zq                -
# | Version: python3.7      -
# | Time: 2020-03-09 20:48                
# +--------------------------
from peewee import *

db = MySQLDatabase("spider_csdn", host="47.111.17.68", port=3306, user="spider_csdn", password="wuhu@888")


class BaseModel(Model):
    class Meta:
        database = db


# 设计数据表的时候有几个重要点
# 1. char类型要设置最大长度,默认255
# 2. 对于无法确定最大长度的字段,可以设置为 Text
# 3. 设计表的时候,采集到的数据要尽量先做格式化处理
# 4. default 和 null=True的情况

# 文章列表
class Topic(BaseModel):
    title = CharField()  # 标题
    content = TextField(default='')  # 内容
    id = IntegerField(primary_key=True)  # id
    author = CharField(default='')  # 作者˚
    create_time = DateTimeField()  # 创建时间
    answer_nums = IntegerField(default=0)  # 回复数量
    click_nums = IntegerField(default=0)  # 点击数量
    praised_nums = IntegerField(default=0)  # 点赞数
    jtl = FloatField(default=0.0)  # 结帖率
    score = IntegerField(default=0)  # 赏分
    status = CharField()  # 状态
    last_answer_time = DateField()  #最后回复时间


# 具体文章表
class Answer(BaseModel):
    topic_id = IntegerField()  # 文章id
    author = CharField()  # 回答者姓名
    content = TextField()  # 回答内容
    create_time = DateTimeField()  # 回答时间
    praised_nums = IntegerField(default=0)  # 点赞数


# 人员表
class Author(BaseModel):
    name = CharField()
    id = CharField(primary_key=True)
    click_nums = IntegerField(default=0)  # 访问数
    original_nums = IntegerField(default=0)  # 原创数
    forward_nums = IntegerField(default=0)  # 转发数
    rate = IntegerField(default=1)  # 排名
    answer_nums = IntegerField(default=0)  # 评论数
    parised_nums = IntegerField(default=0)  # 获赞数
    desc = TextField(null=True)  # 简介
    industry = CharField(null=True)  # 行业
    location = CharField(null=True)  # 位置
    follower_nums = IntegerField(default=0)  # 粉丝数
    following_nums = IntegerField(default=0)  # 关注数


if __name__ == "__main__":
    db.create_tables([Topic, Answer, Author])
